import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import * as THREE from "three";
export default {
  gltf: function (renderer, camera, mesh, scene) {
    // 创建GLTF加载器对象
    // camera.position.set(200, 200, 200);
    const loader = new GLTFLoader();
    loader.load("/models/wood_table_001_4k.gltf", function (gltf) {
      console.log("控制台查看加载gltf文件返回的对象结构", gltf);
      console.log("gltf对象场景属性", gltf.scene);
      // 返回的场景对象gltf.scene插入到threejs场景中
      //   gltf.scene.position.y = 1;
      //   scene.add(gltf.scene);

      const scene1 = gltf.scene;
      const box = new THREE.Box3().setFromObject(scene1);
      const x = box.max.x - box.min.x;
      const y = box.max.y - box.min.y;
      const z = box.max.z - box.min.z;
      const maxDim = Math.max(x, y, z);
      const scale = 250 / maxDim;
      scene1.scale.set(scale, scale, scale);
      // scene.scale.set(25, 25, 25)
      scene.add(scene1);
      const clock = new THREE.Clock();
      const model = gltf.scene.children[0];

    //   function animate() {
    //     const delta = clock.getDelta();
    //     model.rotation.y += delta * Math.PI / 2
    //     renderer.render(scene, camera); //执行渲染操作
    //     requestAnimationFrame(animate); //请求再次执行渲染函数render，渲染下一帧
    //   }
    //   animate();
    });
  },
};
